package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.domain.Result;
import com.dongdong.em.ResultEnum;
import com.dongdong.pojo.PageBean;
import com.dongdong.pojo.TbTypeTemplate;
import com.dongdong.service.TbTypeTemplateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("tbTypeTemplateController")
public class TbTypeTemplateController {
   @Reference
    private TbTypeTemplateService tbTypeTemplateService;

    @RequestMapping("getShow")
    public String getShow(){
        return "/admin/type_template";
    }
    @RequestMapping("getInfo")
    @ResponseBody
    public Result getInfo( String name,@RequestParam(defaultValue = "1",required = false)Integer pageNumber,@RequestParam(defaultValue = "3")Integer pageSize){
          PageBean<TbTypeTemplate> pageBean =tbTypeTemplateService.getInfo(name,pageNumber,pageSize);
        return Result.buildResult(ResultEnum.SUCCESS).setData(pageBean);
    }
    @RequestMapping("save")
    @ResponseBody
    public Result save(TbTypeTemplate tbTypeTemplate){
          tbTypeTemplateService.save(tbTypeTemplate);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
    @RequestMapping("deleteAll")
    @ResponseBody
    public Result deleteAll(@RequestParam("ids[]")Long[] ids){
        tbTypeTemplateService.deleteAll(ids);
        return Result.buildResult(ResultEnum.SUCCESS);
    }
    @RequestMapping("toUpdate")
    @ResponseBody
    public Result toUpdate(Long id){
        TbTypeTemplate tbTypeTemplate =  tbTypeTemplateService.toUpdate(id);
        return Result.buildResult(ResultEnum.SUCCESS).setData(tbTypeTemplate);
    }
    @RequestMapping("update")
    @ResponseBody
    public Result update(TbTypeTemplate tbTypeTemplate){
        tbTypeTemplateService.update(tbTypeTemplate);
        return Result.buildResult(ResultEnum.SUCCESS);
    }

}
